//
//  YFAlertHelper.m
//  SquashSpark
//
//  Created by Coollang on 2017/11/10.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "YFAlertHelper.h"


@implementation YFAlertHelper
+ (zhPopupController *)zhpresentEaseInOutAlertView:(UIView *)alertView allowPan:(BOOL)allowPan dismissTouchMask:(BOOL)touchmaskDismiss {
    zhPopupController *zhPopVc = [self zhPresentInView:nil alertView:alertView maskType:zhPopupMaskTypeBlackTranslucent slideStyle:zhPopupSlideStyleShrinkInOut allowPan:allowPan displayTime:0];
    zhPopVc.maskAlpha = 0.5;
    zhPopVc.dismissOnMaskTouched = touchmaskDismiss;
    return zhPopVc;
}

#pragma mark - zhAlert showStyle1
+ (zhPopupController *)zhPresentInView:(UIView *)view alertView:(UIView *)alertView maskType:(zhPopupMaskType)maskType slideStyle:(zhPopupSlideStyle)slideStyle allowPan:(BOOL)allowPan displayTime:(NSTimeInterval)dispalyTime {
    zhPopupController *zhVc = [zhPopupController popupControllerWithMaskType:maskType];
    zhVc.slideStyle = slideStyle;
    zhVc.allowPan = allowPan;
    if (dispalyTime <= 0) {
        [zhVc presentContentView:alertView duration:0.55 springAnimated:YES inView:view];
    }else {
        [zhVc presentContentView:alertView duration:0.75 springAnimated:YES inView:view displayTime:dispalyTime];
    }
    return zhVc;
}

+ (PopupViewController *)showPresentInView:(UIViewController *)parentViewController alertView:(UIView *)alertView withAlertViewFrame:(CGRect)alertViewFrame animationType:(DetailViewControllerPresentAnimationType)animationType tapMaskViewDismiss:(BOOL)tapMaskView {
    PopupViewController *popVc = [[PopupViewController alloc] init];
    popVc.popupView = alertView;
    popVc.popupView.frame = alertViewFrame;
    [popVc.view addSubview:popVc.popupView];
    if (alertViewFrame.origin.x + alertViewFrame.origin.y == 0) {
        popVc.popupView.center = popVc.view.center;
    }
    popVc.view.backgroundColor = kMaskViewBgColor;
    if (parentViewController == nil) {
        AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        parentViewController = appdelegate.window.rootViewController;
    }
    popVc.isTapCoverViewDismiss = tapMaskView;
    [popVc presentInParentViewController:parentViewController animationType:animationType];
    
    return popVc;
}

#pragma mark - 系统自带弹框
+ (UIAlertController *)showAlertController:(UIViewController *)controller Title:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle defalutTitle:(NSString *)defaultTitle cancelAction:(void(^)(UIAlertAction *action))cancelAction defalutAction:(void(^)(UIAlertAction *action))defalutAction {
    return [self showTwoAlertController:controller Title:title message:message cancelTitle:cancelTitle defalutTitle:defaultTitle defaultBtnStyle:UIAlertActionStyleDefault cancelAction:cancelAction defalutAction:defalutAction];
}

+ (UIAlertController *)showTwoAlertController:(UIViewController *)controller Title:(NSString *)title message:(NSString *)message cancelTitle:(NSString *)cancelTitle defalutTitle:(NSString *)defaultTitle defaultBtnStyle:(UIAlertActionStyle)defaultBtnStyle cancelAction:(void(^)(UIAlertAction *action))cancelAction defalutAction:(void(^)(UIAlertAction *action))defalutAction {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    if (cancelTitle.length <= 0 && defaultTitle.length <= 0) {
        cancelTitle = cancelTitle.length > 0 ? cancelTitle:@"OK";
    }
    
    if (cancelTitle) {
        UIAlertAction *cancelItem = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (cancelAction) {
                cancelAction(action);
            }
        }];
        [alertController addAction:cancelItem];
    }
    
    if (defaultTitle.length > 0) {
        UIAlertAction *defalut = [UIAlertAction actionWithTitle:defaultTitle style:defaultBtnStyle handler:^(UIAlertAction * _Nonnull action) {
            if (defalutAction) {
                defalutAction(action);
            }
        }];
        [alertController addAction:defalut];
    }
    
    if (controller == nil) {
        AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        controller = appdelegate.window.rootViewController;
    }
    [controller presentViewController:alertController animated:YES completion:nil];
    return alertController;
    
}


@end
